<?php
	// Fichier de gestion/config base de données
	require "gestion_bdd.php";
?>

<?php
	try {
		// On prolonge la session
		session_start();
		// On test si la variable de session existe et contient une valeur
		if(empty($_SESSION['login'])) 
		{
			// Si inexistante ou nulle, on redirige vers le formulaire de login
			header('Location: index.php');
			exit();
		}	
	} catch (Exception $e) {
		$error = $error.$e->getMessage()."\n";
	}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
	<head>
    <meta http-equiv="Content-Type" content="text/html;  charset=UTF-8" /> 
	<title>Détails</title> 
	<link rel="icon" type="image/png" href="images/Favicon.png" /> 
	
	<link rel="stylesheet" type="text/css" media="all" href="Styles/bootstrap.css" />
	<link rel="stylesheet" type="text/css" media="all" href="Styles/style.css" />
	
	<meta name="description" content="" /> 
	<meta name="keywords" content=""> 
	<meta name="url" content=""> 
	<meta name="robots" content="all">

	<script src="Javascripts/jquery.min.js" type="text/javascript"></script>
	
	</head>
	<body>  
		<?php
			//Ajout du menu
			include 'headMenu.php';
		?>  
  
		<div class="well" id="corps">
			<div class="page-header">
				<h2 class="center">Détail de l'offre</h2>
			</div>	
			
			<table class="bordered-table">
				<?php
					if (isset ($_GET["id"])) { 
						$id_offres = $_GET["id"];
						
						$sql_id_user = "SELECT ID_Utilisateurs FROM Offres WHERE ID_offres=".$id_offres."";
						$result_id_user = mysql_query($sql_id_user) or die('Erreur SQL !<br>'.$sql_id_user.'<br>'.mysql_error());											
						$row = mysql_fetch_row($result_id_user);
						$id_user = $row[0];
						
						$sql_nom_user = "SELECT Nom FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
						$result_nom_user = mysql_query($sql_nom_user) or die('Erreur SQL !<br>'.$sql_nom_user.'<br>'.mysql_error());											
						$row2 = mysql_fetch_row($result_nom_user);
						$nom_user = $row2[0];
						
						$sql_adresse = "SELECT Adresse FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
						$result_adresse = mysql_query($sql_adresse) or die('Erreur SQL !<br>'.$sql_adresse.'<br>'.mysql_error());											
						$row5 = mysql_fetch_row($result_adresse);
						$adresse = $row5[0];
						
						$sql_ville = "SELECT Ville FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
						$result_ville = mysql_query($sql_ville) or die('Erreur SQL !<br>'.$sql_ville.'<br>'.mysql_error());											
						$row6 = mysql_fetch_row($result_ville);
						$ville = $row6[0];
						
						$sql_cp = "SELECT Code_Postal FROM Utilisateurs WHERE ID_Utilisateurs=".$id_user."";
						$result_cp = mysql_query($sql_cp) or die('Erreur SQL !<br>'.$sql_cp.'<br>'.mysql_error());											
						$row7 = mysql_fetch_row($result_cp);
						$cp = $row7[0];						
						
						$sql_description = "SELECT Description FROM Offres WHERE ID_offres=".$id_offres."";
						$result_description= mysql_query($sql_description) or die('Erreur SQL !<br>'.$sql_description.'<br>'.mysql_error());											
						$row3 = mysql_fetch_row($result_description);
						$description = $row3[0];
						
						$sql_date = "SELECT Date_Fin_Reservation FROM Offres WHERE ID_offres=".$id_offres."";
						$result_date = mysql_query($sql_date) or die('Erreur SQL !<br>'.$sql_date.'<br>'.mysql_error());											
						$row4 = mysql_fetch_row($result_date);
						$date = $row4[0];
						
						$adresse_complete = $adresse." - ".$cp." - ".$ville;
						
					} else { 
						$id_offres = null;
					}					
				?>				
				
				<thead>
					<tr>
						<th> ID de l'offre </th>
						<th><?php echo $id_offres; ?></th>
					</tr>
					<tr>
						<th> Utilisateur </th>
						<td><?php echo $nom_user; ?></td>
					</tr>
					<tr>
						<th> Adresse </th>
						<td><?php echo $adresse_complete; ?></td>
					</tr>
					<tr>
						<th> Description </th>
						<td><?php echo $description; ?></td>
					</tr>
					<tr>
						<th> Date de fin de réservation </th>
						<td><?php echo $date; ?></td>
					</tr>				
				</thead>
			</table>
			
			<br>
			<div class="span3">
				<input class="btn primary" id="btnRetour" type="submit" name="submit" onclick="window.history.back();"  value="Retour"/>
			</div>			
		</div>
	</body>
</html>